package edu.ufop.vaadin.helloworld.view;

import com.vaadin.annotations.Theme;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.shared.ui.MarginInfo;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Button;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.themes.Reindeer;

@SuppressWarnings("serial")
@Theme("msg")
public class Mensagem extends CustomComponent implements View {

	public static final String NAME = "msg";
	private static String s=null,name=null;
	private static Button button;
	private static Mensagem ref;
	
	@Override
	public void enter(ViewChangeEvent event) {
		ref = this;
		VerticalLayout fields = new VerticalLayout(button);
		fields.setCaption(s);
		fields.setSpacing(true);
		fields.setMargin(new MarginInfo(true, true, true, false));
		fields.setSizeUndefined();		
		// The view root layout
		VerticalLayout viewLayout = new VerticalLayout(fields);
		viewLayout.setSizeFull();
		viewLayout.setComponentAlignment(fields, Alignment.MIDDLE_CENTER);
		viewLayout.setStyleName(Reindeer.LAYOUT_BLUE);
		setCompositionRoot(viewLayout);
	}
	public static void setMensagem(String st,String r){
		s = st;		
		button = new Button("Voltar");
		name = r;
		button.addClickListener( new Button.ClickListener(){
			public void buttonClick(ClickEvent event){			
				ref.getUI().getNavigator().navigateTo(name);//
			}
		});
	}
}
